package movilmax.sia_corp.interceptor;

//import java.util.Iterator;
//import java.util.Map;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class MyInterceptor implements Interceptor{
		private static final long serialVersionUID = 1L;
	    public String intercept(ActionInvocation invocation) throws Exception {
	        String className = invocation.getAction().getClass().getName();
	        long startTime = System.currentTimeMillis();
	        System.out.println("Antes de llamar la accion: " + className);
	        /*Map<String, Object> pars=invocation.getInvocationContext().getParameters();
	        for (final Iterator<String> it =pars.keySet().iterator(); it.hasNext();) {
	        		final String par = it.next();
	        		System.out.print("parametro: " + par);
	        }*/
	        String result = invocation.invoke();
	        long endTime = System.currentTimeMillis();
	        System.out.println("Despues de llamar el accion: " + className + " Tiempo que tomo: " + (endTime - startTime) + " ms");
	        return result;
	    }
	 
	    public void destroy() {
	        System.out.println("Destroying MyLoggingInterceptor...");
	    }
	    public void init() {
	        System.out.println("Initializing MyLoggingInterceptor...");
	    }
}
